package com.trm.util;

import java.util.List;
import java.util.Map;

import com.common.util.jdbc.BaseDao;

public class TrmUtils {
    /**
     * 获得省份信息
     * 
     * @return
     */
    public List<Map<String, Object>> getProvinceList() {
        List<Map<String, Object>> list = null;
        String sql = "select id, provinceid, province from provinces";
        BaseDao dao = new BaseDao();
        list = dao.executeSqlToList(sql);
        return list;
    }

    /**
     * 获得市信息
     * 
     * @param provinceid
     * @return
     */
    public List<Map<String, Object>> getCityList(String provinceid) {
        List<Map<String, Object>> list = null;
        String sql = "select id, cityid, city, provinceid from cities";
        if (provinceid != null && !"".equals(provinceid)) {
            sql += " where provinceid = " + provinceid;
        }
        BaseDao dao = new BaseDao();
        list = dao.executeSqlToList(sql);
        return list;
    }

    /**
     * 
     * mamingyuan 2018年5月28日
     * 
     * @param provinceid
     * @param cityid
     * @return
     */
    public List<Map<String, Object>> getAreasList(String provinceid, String cityid) {
        List<Map<String, Object>> list = null;
        String sql = "select id, areaid, area, cityid from areas";
        if (cityid != null && !"".equals(cityid)) {
            if (sql.contains(" where ")) {
                sql += " and ";
            } else {
                sql += " where ";
            }
            sql += " where cityid = " + cityid;
        } else {
            if (provinceid != null && !"".equals(provinceid)) {
                sql += " where cityid in (select cityid from cities where provinceid = " + provinceid + ")";
            }
        }
        BaseDao dao = new BaseDao();
        list = dao.executeSqlToList(sql);
        return list;
    }
}
